package com.azhon.entry.config;

import com.azhon.appupdate.base.BaseHttpDownloadManager;
import com.azhon.appupdate.config.UpdateConfiguration;
import com.azhon.appupdate.listener.OnButtonClickListener;
import com.azhon.appupdate.listener.OnDownloadListener;
import ohos.event.notification.NotificationSlot;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.*;

public class UpdateConfigurationTest {

    private final UpdateConfiguration updateConfiguration = new UpdateConfiguration();
    private BaseHttpDownloadManager baseHttpDownloadManager;
    private OnDownloadListener onDownloadListener;
    private NotificationSlot notificationSlot;
    private OnButtonClickListener onButtonClickListener;

    @Before
    public void setUp() throws Exception {
        baseHttpDownloadManager = new BaseHttpDownloadManager() {
            @Override
            public void download(String apkUrl, String apkName, OnDownloadListener listener) {

            }

            @Override
            public void cancel() {

            }

            @Override
            public void release() {

            }
        };

        onDownloadListener = new OnDownloadListener() {
            @Override
            public void start() { }

            @Override
            public void downloading(int progress) { }

            @Override
            public void done(File apk) { }

            @Override
            public void cancel() { }

            @Override
            public void error(Exception e) { }
        };

        notificationSlot = new NotificationSlot("1", "NotificationSlot", 1);

        onButtonClickListener = new OnButtonClickListener() {
            @Override
            public void onButtonClick(int id) {

            }
        };
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void setNotifyId() {
        UpdateConfiguration config = updateConfiguration.setNotifyId(1);
        assertSame(updateConfiguration, config);
        int num = updateConfiguration.getNotifyId();
        assertEquals(1, num);
    }

    @Test
    public void setHttpManager() {
        UpdateConfiguration config = updateConfiguration.setHttpManager(baseHttpDownloadManager);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getHttpManager() {
        UpdateConfiguration config = updateConfiguration.setHttpManager(baseHttpDownloadManager);
        assertSame(baseHttpDownloadManager, config.getHttpManager());
    }

    @Test
    public void setEnableLog() {
        UpdateConfiguration config = updateConfiguration.setEnableLog(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void setOnDownloadListener() {
        UpdateConfiguration config = updateConfiguration.setOnDownloadListener(onDownloadListener);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getOnDownloadListener() {
        UpdateConfiguration config = updateConfiguration.setOnDownloadListener(onDownloadListener);
        assertEquals(1, config.getOnDownloadListener().size());

    }

    @Test
    public void setJumpInstallPage() {
        UpdateConfiguration config = updateConfiguration.setJumpInstallPage(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void isJumpInstallPage() {
        UpdateConfiguration config = updateConfiguration.setJumpInstallPage(true);
        assertTrue(config.isJumpInstallPage());
    }

    @Test
    public void setNotificationChannel() {
        UpdateConfiguration config = updateConfiguration.setNotificationChannel(notificationSlot);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getNotificationChannel() {
        UpdateConfiguration config = updateConfiguration.setNotificationChannel(notificationSlot);
        assertSame(notificationSlot, config.getNotificationChannel());
    }

    @Test
    public void setShowNotification() {
        UpdateConfiguration config = updateConfiguration.setShowNotification(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void isShowNotification() {
        UpdateConfiguration config = updateConfiguration.setShowNotification(true);
        assertTrue(config.isShowNotification());
    }

    @Test
    public void setForcedUpgrade() {
        UpdateConfiguration config = updateConfiguration.setForcedUpgrade(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void isForcedUpgrade() {
        UpdateConfiguration config = updateConfiguration.setForcedUpgrade(true);
        assertTrue(config.isForcedUpgrade());
    }

    @Test
    public void setShowBgdToast() {
        UpdateConfiguration config = updateConfiguration.setShowBgdToast(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void isShowBgdToast() {
        UpdateConfiguration config = updateConfiguration.setShowBgdToast(true);
        assertTrue(config.isShowBgdToast());
    }

    @Test
    public void setDialogImage() {
        UpdateConfiguration config = updateConfiguration.setDialogImage(1);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getDialogImage() {
        UpdateConfiguration config = updateConfiguration.setDialogImage(1);
        assertEquals(1, config.getDialogImage());
    }

    @Test
    public void setDialogButtonColor() {
        UpdateConfiguration config = updateConfiguration.setDialogButtonColor(1);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getDialogButtonColor() {
        UpdateConfiguration config = updateConfiguration.setDialogButtonColor(1);
        assertEquals(1, config.getDialogButtonColor());
    }

    @Test
    public void setDialogButtonTextColor() {
        UpdateConfiguration config = updateConfiguration.setDialogButtonTextColor(1);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getDialogButtonTextColor() {
        UpdateConfiguration config = updateConfiguration.setDialogButtonTextColor(1);
        assertEquals(1, config.getDialogButtonTextColor());
    }

    @Test
    public void setDialogProgressBarColor() {
        UpdateConfiguration config = updateConfiguration.setDialogProgressBarColor(1);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getDialogProgressBarColor() {
        UpdateConfiguration config = updateConfiguration.setDialogProgressBarColor(1);
        assertEquals(1, config.getDialogProgressBarColor());
    }

    @Test
    public void setButtonClickListener() {
        UpdateConfiguration config = updateConfiguration.setButtonClickListener(onButtonClickListener);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void getOnButtonClickListener() {
        UpdateConfiguration config = updateConfiguration.setButtonClickListener(onButtonClickListener);
        assertSame(onButtonClickListener, config.getOnButtonClickListener());
    }

    @Test
    public void setUsePlatform() {
        UpdateConfiguration config = updateConfiguration.setUsePlatform(true);
        assertSame(updateConfiguration, config);
    }

    @Test
    public void isUsePlatform() {
        UpdateConfiguration config = updateConfiguration.setUsePlatform(true);
        assertTrue(config.isUsePlatform());
    }
}